//点击输入框会有相应样式的变化，用到了失去焦点的事件
var first = document.querySelector(".first");
var second = document.querySelector(".second");
var account = document.querySelector(".account");
var password = document.querySelector(".password");
account.onclick = function () {
  first.style.borderColor = "red";
  account.onblur = function () {
    first.style.borderColor = "black";
  };
};
password.onclick = function () {
  second.style.borderColor = "red";
  password.onblur = function () {
    second.style.borderColor = "black";
  };
};
//两个页面的相互返回
var zhuCe_font = document.querySelector(".zhuCe_font");
var login_div = document.querySelector(".login_div");
var zhuCe_back = document.querySelector(".zhuCe_back");
var zhuCe = document.querySelector(".zhuCe");
zhuCe_font.onclick = function () {
  login_div.style.display = "none";
  zhuCe.style.display = "block";
};
zhuCe_back.onclick = function () {
  login_div.style.display = "block";
  zhuCe.style.display = "none";
};
//登录页面的功能
var dengLu = document.querySelector(".dengLu");
var tip_one = document.querySelector(".tip_one");
var tip_two = document.querySelector(".tip_two");
dengLu.onclick = function () {
  if (password.value == "" || account.value == "") {
    tip_one.style.display = "block";
    account.onclick = function () {
      tip_one.style.display = "none";
    };
    password.onclick = function () {
      tip_one.style.display = "none";
    };
  }
};
//注册页面
var zhuCe_center_account = document.querySelector(".zhuCe_center_account");
var zhuCe_center_password = document.querySelector(".zhuCe_center_password");
var zhuCe_center_password_two = document.querySelector(
  ".zhuCe_center_password_two"
);
var zhuCe_center_account_div = document.querySelector(
  ".zhuCe_center_account_div"
);
var zhuCe_center_password_div = document.querySelector(
  ".zhuCe_center_password_div"
);
var zhuCe_center_password_div_two = document.querySelector(
  ".zhuCe_center_password_div_two"
);
var zhuCe_center_email = document.querySelector(".zhuCe_center_email");
var zhuCe_center_email_div = document.querySelector(".zhuCe_center_email_div");
var zhuCe_center_identifyingCode_div = document.querySelector(
  ".zhuCe_center_identifyingCode_div"
);
var zhuCe_center_identifyingCode = document.querySelector(
  ".zhuCe_center_identifyingCode"
);

//点击三个输入框会有相应样式的变化，用到了失去焦点的事件
zhuCe_center_account.onclick = function () {
  zhuCe_center_account_div.style.borderColor = "red";
  zhuCe_center_account.onblur = function () {
    zhuCe_center_account_div.style.borderColor = "black";
  };
};
zhuCe_center_password.onclick = function () {
  zhuCe_center_password_div.style.borderColor = "red";
  zhuCe_center_password.onblur = function () {
    zhuCe_center_password_div.style.borderColor = "black";
  };
};
zhuCe_center_password_two.onclick = function () {
  zhuCe_center_password_div_two.style.borderColor = "red";
  zhuCe_center_password_two.onblur = function () {
    zhuCe_center_password_div_two.style.borderColor = "black";
  };
};
zhuCe_center_email.onclick = function () {
  zhuCe_center_email_div.style.borderColor = "red";
  zhuCe_center_email.onblur = function () {
    zhuCe_center_email_div.style.borderColor = "black";
  };
};
zhuCe_center_identifyingCode.onclick = function () {
  zhuCe_center_identifyingCode_div.style.borderColor = "red";
  zhuCe_center_identifyingCode.onblur = function () {
    zhuCe_center_identifyingCode_div.style.borderColor = "black";
  };
};
//点击注册事件
var zhuCe_bottom = document.querySelector(".zhuCe_bottom");
var zhuCe_center_hidden_five = document.querySelector(
  ".zhuCe_center_hidden_five"
);
zhuCe_center_hidden_five.onclick = function () {
  alert("a");
  $.ajax({
    type: "post",
    url: "http://118.195.129.130:3000/user/getMailCode",
    data: {
      mail: $(".zhuCe_center_email").val(),
    },
    success: function (data) {
      console.log(data);
    },
    error: function (err) {
      console.log(err);
    },
  });
};
  //获取验证码之后的注册功能
  zhuCe_bottom.onclick = function () {
    if (
      zhuCe_center_account.value == "" ||
      zhuCe_center_password.value == "" ||
      zhuCe_center_password_two.value == "" ||
      zhuCe_center_email.value == "" ||
      zhuCe_center_identifyingCode.value == ""
    ) {
      alert("您未输入全部的内容");
      if (zhuCe_center_password.value != zhuCe_center_password_two.value) {
        alert("输入的两次密码不一样！");
      }
    } else {
      //注册
      $.ajax({
        type: "post",
        url: "http://118.195.129.130:3000/user/reg",
        data: {
          us: $(".zhuCe_center_account").val(),
          ps: $(".zhuCe_center_password").val(),
          mail: $(".zhuCe_center_email").val(),
          code: $(".zhuCe_center_identifyingCode").val(),
        },
        success: function (data) {
          console.log(data);
          if (data.err === 0) {
            alert("登录成功！");
            console.log(data);
          } else {
            alert("注册失败！");
          }
        },
        error: function (err) {
          console.log(err);
        },
      });
    }
  };
// // 登录;
$(".dengLu").click(function () {
  $.ajax({
    type: "post",
    url: "http://118.195.129.130:3000/user/login",
    data: {
      us: $(".zhuCe_center_account").val(),
      ps: $(".zhuCe_center_password").val(),
    },
    success: function (data) {
      if (data.err === 0) {
        console.log(data);
        alert("登录成功！");
        $(location).attr("href", "../html/manage.html");
        // $(location).attr('href') "../html/manage.html";
      } else {
        alert("用户名或密码错误！");
        // console.log(data);
      }
    },
    error: function (err) {
      console.log(err);
    },
  });
});
